package com.yuexunit.finance.member.service;

import java.util.List;

import org.hibernate.criterion.DetachedCriteria;
import org.hibernate.criterion.Restrictions;

import com.yuexunit.finance.member.entity.CommissionScaleTableEntity;
import com.yuexunit.inject.annotation.Implements;
import com.yuexunit.persist.PersistUtil;
import com.yuexunit.persist.annotation.Transactional;
import com.yuexunit.util.DateUtil;

/**
*@version 创建时间：2017年2月21日 上午11:34:12
*@author wenwenlong
*类说明
*/

@Implements(CommissionScaleTableService.class)
public class CommissionScaleTableServiceImpl implements CommissionScaleTableService {
	@Override
	@Transactional
	public Long createCommissionScaleTable(CommissionScaleTableEntity entity) {
		entity.setUpdateDateTime(DateUtil.now());
		entity.setCreateDateTime(DateUtil.now());
		entity.setEnable(Boolean.FALSE);
		PersistUtil.insert(entity);
		return entity.getScaleId();
	}

	@Override
	@Transactional
	public void updateCommissionScaleTable(CommissionScaleTableEntity entity) {
		entity.setUpdateDateTime(DateUtil.now());
		PersistUtil.update(entity);
	}

	@Override
	public CommissionScaleTableEntity inquireCommissionScaleTableDetail(Long scaleId) {
		return PersistUtil.get(CommissionScaleTableEntity.class, scaleId);
	}

	@Override
	public List<CommissionScaleTableEntity> inquireCommissionScaleTable(Long enterpriseId, Long accountId) {
		DetachedCriteria criteria = DetachedCriteria.forClass(CommissionScaleTableEntity.class);
		criteria.add(Restrictions.eq("enterpriseId", enterpriseId));
		if (accountId != null) {
			criteria.add(Restrictions.eq("accountId", accountId));
		}
		return PersistUtil.get(criteria);
	}

	@Override
	@Transactional
	public void deleteCommissionScaleTable(Long scaleId) {
		PersistUtil.delete(CommissionScaleTableEntity.class, scaleId);
	}
}
